//#include <unistd.h>  // for F_ok
#include <glib.h>
#include <stdio.h> 
#include <unistd.h>

#include "config.h"
#include "sys_log.h"

int start_scan_wifi(void)
{
	printf("Start service engine by client\n");
	FILE *fp;

	fp = popen("sudo iwlist wlan0 scan | grep ESSID > ap.txt", "r");
	pclose(fp);

	return 1;
}

int wifi_connect_ap(char* essid, char* pwd)
{
	printf("Start service engine by client\n");
	char path[200] = {0};
	FILE *fp;

	if(!essid) return -1;

	if(NULL != pwd) {
		sprintf(path,"sudo iwconfig wlan0 key %s",pwd);

		fp = popen(path, "r");
		pclose(fp);

		fp = popen("sudo iwconfig wlan0 key open", "r");
		pclose(fp);
	}
	
	sprintf(path,"sudo iwconfig wlan0 essid \"%s\"",essid);
	fp = popen(path, "r");
	pclose(fp);
	
	fp = popen("sudo udhcpc -i wlan0 ", "r");
	pclose(fp);

	return 1;
}

int wifi_disconnect_ap()
{
	printf("Start service engine by client\n");
	char path[200] = {0};
	FILE *fp;
	return 1;
}


